package com.ruoyi.tea.api;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.tea.domain.TeaAnchor;
import com.ruoyi.tea.domain.TeaProposal;
import com.ruoyi.tea.domain.TeaUser;
import com.ruoyi.tea.service.ITeaHelpService;
import com.ruoyi.tea.service.ITeaProposalService;
import com.ruoyi.tea.service.ITeaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 帮助信息API
 *
 * @author wangfeng
 * @time 2022年08月04日21:56:07
 */
@Controller
@RequestMapping("/wx/api/help")
public class HelpApiController {

    @Autowired
    private ITeaHelpService iTeaHelpService;

    @Autowired
    private ITeaProposalService iTeaProposalService;

    @Autowired
    private ITeaUserService iTeaUserService;

    @RequestMapping("/info")
    @ResponseBody
    public AjaxResult help(@RequestBody JSONObject jsonObject) {
        return AjaxResult.success(iTeaHelpService.oneHelp());
    }

    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestBody TeaProposal teaProposal) {
        TeaUser teaUser = new TeaUser();
        teaUser.setOpenId(teaProposal.getOpenId());
        List<TeaUser> teaUserList = iTeaUserService.selectTeaUserList(teaUser);
        if (teaUserList != null && teaUserList.size() != 0) {
            teaProposal.setName(teaUserList.get(0).getName());
            teaProposal.setNickName(teaUserList.get(0).getNickName());
            teaProposal.setPhone(teaUserList.get(0).getPhone());
            teaProposal.setUserCode(teaUserList.get(0).getUserCode());
        }
        iTeaProposalService.insertTeaProposal(teaProposal);
        return AjaxResult.success();
    }
}
